//
//  ViewController.m
//  Layer
//
//  Created by hyl on 16/7/1.
//  Copyright © 2016年 hyl. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@property (weak, nonatomic) IBOutlet UIView *lView;
@property (weak, nonatomic) IBOutlet UIImageView *imageView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
//    [self layView];
//    [self imageLayer];
    [self imageLayer2];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - layerView
-(void)layView{
    //背景颜色
    self.lView.layer.backgroundColor=[UIColor yellowColor].CGColor;
    //线宽度
    self.lView.layer.borderWidth=1;
    //图层的颜色都是核心绘图框架，cg开头
    //线条颜色
    self.lView.layer.borderColor=[UIColor redColor].CGColor;
    //阴影不透明度
    self.lView.layer.shadowOpacity=1;
    //阴影偏移量
    self.lView.layer.shadowOffset=CGSizeMake(5, 5);
    //圆角
    self.lView.layer.cornerRadius=20;
}

-(void) imageLayer{
    CALayer *layer=[CALayer layer];
    layer.frame=CGRectMake(0, 0, 200, 200);
    layer.backgroundColor=[UIColor redColor].CGColor;
    //    layer.contents=[UIImage imageNamed:@"阿狸头像"];
    layer.contents=(id)[UIImage imageNamed:@"阿狸头像"].CGImage;
    [self.imageView.layer addSublayer:layer];
}

-(void) imageLayer2{
    CALayer *layer=[CALayer layer];
    layer.frame=CGRectMake(0, 0, 200, 200);
    layer.backgroundColor=[UIColor redColor].CGColor;
    layer.cornerRadius=100;
    //    layer.contents=[UIImage imageNamed:@"阿狸头像"];
    layer.contents=(id)[UIImage imageNamed:@"阿狸头像"].CGImage;
    //超出主层边框的内容全部裁剪掉
    layer.masksToBounds=YES;
    //添加边框
    layer.borderColor=[UIColor greenColor].CGColor;
    layer.borderWidth=2;
    [self.imageView.layer addSublayer:layer];
}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    //图层的3D变换
    //缩放
    [UIView animateWithDuration:1 animations:^{
        self.lView.layer.transform=CATransform3DScale(self.lView.layer.transform, 0.5, 0.5, 0.5);
        
        self.lView.layer.transform=CATransform3DMakeRotation(M_PI, 1, 1, 0);
    }];
    
    //
}
@end
